package com.ctsi.commons.event.config;

import com.ctsi.commons.util.UtilMisc;
import com.ctsi.commons.util.UtilValidate;

import java.io.Serializable;

/**
 * 事件源对象
 */
public class Event implements Serializable {
	private static final long serialVersionUID = 7576439723542948623L;

	private String classKey;

	private String eventid;

	private String fac;

	private String condition;

	private boolean isSync;

	private String name;
	
	private String moduleId;
	
	private String id;
	
	private boolean isSingleton=true;
	
	private String scope;
	
	private boolean isEnable=true;
	public boolean isEnsable()
	{
		return isEnable;
	}
	public void setisEnable(String enable)
	{
		isEnable= UtilMisc.checkBoolean(enable, true);
	}
	public String getClassKey() {
		return classKey;
	}

	public void setClassKey(String classKey) {
		this.classKey = classKey;
	}

	public String getEventid() {
		return eventid;
	}

	public void setEventid(String eventid) {
		this.eventid = eventid;
	}

	public String getFac() {
		return fac;
	}

	public void setFac(String fac) {
		this.fac = fac;
	}

	public String getCondition() {
		return condition;
	}

	public void setCondition(String condition) {
		this.condition = condition;
	}

	public boolean isSync() {
		return isSync;
	}

	public void setSync(boolean isSync) {
		this.isSync = isSync;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getModuleId() {
		return moduleId;
	}

	public void setModuleId(String moduleId) {
		this.moduleId = moduleId;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		assert(UtilValidate.isNotEmpty(id));
		this.id = id;
	}
	public String toString()
	{
      return name;		
	}

	public boolean isSingleton() {
		return isSingleton;
	}

	public String getScope() {
		return scope;
	}

	public void setScope(String scope) {
		if (UtilValidate.isNotEmpty(scope))
		{
			this.scope = scope;
			isSingleton=!"prototype".equals(scope);			
		}

	}
	//事件源,默认本地,注意原始设计是eventId全局,所以此字段部参与equals
	private String systemName;
	
	public String getSystemName() {
		return systemName;
	}
	public void setSystemName(String systemName) {
		this.systemName = systemName;
	}
	
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!(obj instanceof Event) || id == null)
			return false;
		return id.equals(((Event)obj).id);
	}

	public int hashCode() {
		return id == null ? super.hashCode() : id.hashCode();
	}
}
